﻿<common:LayoutAwarePage
    x:Name="pageRoot"
    x:Class="Looptribe.Moodlin8.View.CoursePage"
    DataContext="{Binding Course, Source={StaticResource Locator}}"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Looptribe.Moodlin8.View"
    xmlns:common="using:Looptribe.Moodlin8.Common"
    xmlns:looptribe="using:Looptribe.WinRT.Toolkit"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:h2xaml="using:Html2Xaml"
    mc:Ignorable="d">

    <Page.Resources>
        <!-- Styles -->
        <Style x:Key="CourseSectionTitleStyle" TargetType="TextBlock">
            <Setter Property="FontFamily" Value="{StaticResource ContentControlThemeFontFamily}"/>
            <Setter Property="TextTrimming" Value="WordEllipsis"/>
            <Setter Property="TextWrapping" Value="NoWrap"/>
            <Setter Property="Typography.StylisticSet20" Value="True"/>
            <Setter Property="Typography.DiscretionaryLigatures" Value="True"/>
            <Setter Property="Typography.CaseSensitiveForms" Value="True"/>
            <Setter Property="FontSize" Value="26.667"/>
            <Setter Property="LineStackingStrategy" Value="BlockLineHeight"/>
            <Setter Property="FontWeight" Value="Normal"/>
            <Setter Property="LineHeight" Value="30"/>
            <Setter Property="RenderTransform">
                <Setter.Value>
                    <TranslateTransform X="-1" Y="6"/>
                </Setter.Value>
            </Setter>
            <Setter Property="Foreground" Value="{StaticResource MoodleSectionTitleColor}"></Setter>
        </Style>
        <Style x:Key="CourseOverviewSectionStyle" TargetType="TextBlock">
            <Setter Property="FontFamily" Value="{StaticResource ContentControlThemeFontFamily}"/>
            <Setter Property="TextTrimming" Value="WordEllipsis"/>
            <Setter Property="TextWrapping" Value="NoWrap"/>
            <Setter Property="Typography.StylisticSet20" Value="True"/>
            <Setter Property="Typography.DiscretionaryLigatures" Value="True"/>
            <Setter Property="Typography.CaseSensitiveForms" Value="True"/>
            <Setter Property="FontSize" Value="16"/>
            <Setter Property="LineStackingStrategy" Value="BlockLineHeight"/>
            <Setter Property="FontWeight" Value="Bold"/>
            <Setter Property="LineHeight" Value="30"/>
            <Setter Property="RenderTransform">
                <Setter.Value>
                    <TranslateTransform X="-1" Y="6"/>
                </Setter.Value>
            </Setter>
            <Setter Property="Foreground" Value="White"/>
            <Setter Property="Margin" Value="20,30,0,0"/>
        </Style>
        <Style x:Key="SectionStyle" TargetType="Grid">
            <Setter Property="Margin" Value="40,0,40,0"/>
        </Style>

        <Style x:Key="InnerSectionContainerStyle" TargetType="StackPanel">
            <Setter Property="Margin" Value="0,15,0,0" />
        </Style>
        <Style x:Key="CourseInnerSectionTitleStyle" TargetType="TextBlock" BasedOn="{StaticResource BaselineTextStyle}">
            <Setter Property="FontWeight" Value="Bold"/>
        </Style>
        <Style x:Key="CourseOverviewSectionButtonStyle" TargetType="Button">
            <Setter Property="MinWidth" Value="0"/>
            <Setter Property="MinHeight" Value="0"/>
            <Setter Property="FontFamily" Value="{StaticResource ContentControlThemeFontFamily}"/>
            <Setter Property="Typography.StylisticSet20" Value="True"/>
            <Setter Property="Typography.DiscretionaryLigatures" Value="True"/>
            <Setter Property="Typography.CaseSensitiveForms" Value="True"/>
            <Setter Property="FontSize" Value="16"/>
            <Setter Property="FontWeight" Value="Bold"/>
            <Setter Property="RenderTransform">
                <Setter.Value>
                    <TranslateTransform X="-1" Y="6"/>
                </Setter.Value>
            </Setter>
            <Setter Property="Foreground" Value="White"/>
            <Setter Property="Margin" Value="20,30,0,0"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ButtonBase">
                        <Grid Background="Transparent">
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Normal"/>
                                    <VisualState x:Name="PointerOver">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Text" Storyboard.TargetProperty="Foreground">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ApplicationSecondaryForegroundThemeBrush}"/>
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Pressed">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Text" Storyboard.TargetProperty="Foreground">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ApplicationPressedForegroundThemeBrush}"/>
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Disabled">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Text" Storyboard.TargetProperty="Foreground">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ApplicationPressedForegroundThemeBrush}"/>
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                                <VisualStateGroup x:Name="FocusStates">
                                    <VisualState x:Name="Focused">
                                        <Storyboard>
                                            <DoubleAnimation Duration="0" To="1" Storyboard.TargetName="FocusVisualWhite" Storyboard.TargetProperty="Opacity"/>
                                            <DoubleAnimation Duration="0" To="1" Storyboard.TargetName="FocusVisualBlack" Storyboard.TargetProperty="Opacity"/>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Unfocused"/>
                                </VisualStateGroup>
                                <VisualStateGroup x:Name="CheckStates">
                                    <VisualState x:Name="Checked"/>
                                    <VisualState x:Name="Unchecked">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Text" Storyboard.TargetProperty="Foreground">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ApplicationSecondaryForegroundThemeBrush}"/>
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Indeterminate"/>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <ContentPresenter x:Name="Text" Content="{TemplateBinding Content}" />
                            <Rectangle
        						x:Name="FocusVisualWhite"
        						IsHitTestVisible="False"
        						Stroke="{StaticResource FocusVisualWhiteStrokeThemeBrush}"
        						StrokeEndLineCap="Square"
        						StrokeDashArray="1,1"
        						Opacity="0"
        						StrokeDashOffset="1.5"/>
                            <Rectangle
        						x:Name="FocusVisualBlack"
        						IsHitTestVisible="False"
        						Stroke="{StaticResource FocusVisualBlackStrokeThemeBrush}"
        						StrokeEndLineCap="Square"
        						StrokeDashArray="1,1"
        						Opacity="0"
        						StrokeDashOffset="0.5"/>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <!-- Templates -->
        <DataTemplate x:Key="ModuleContentTemplate">
            <Grid Margin="2" Width="360" MinHeight="40">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <Border Background="{StaticResource ListViewItemPlaceholderBackgroundThemeBrush}" Width="40" Height="40">
                    <Image Stretch="UniformToFill" Source="{Binding Module.ModIcon}" />
                    <!--<Image Stretch="UniformToFill">
                        <Image.Source>
                            <Binding Path="FileType" Converter="{StaticResource fileTypeConverter}" />
                        </Image.Source>
                    </Image>-->
                </Border>
                <StackPanel Grid.Column="1" Margin="10,0,0,0">
                    <TextBlock Text="{Binding Module.Name}" Style="{StaticResource ItemTextStyle}" TextWrapping="NoWrap" TextTrimming="None"/>
                    <TextBlock Text="{Binding Content.FileUrl}" Style="{StaticResource ItemTextStyle}" TextWrapping="NoWrap" TextTrimming="None"/>
                </StackPanel>
            </Grid>
        </DataTemplate>
        
        <DataTemplate x:Key="TeacherTemplate">
            <Grid Height="70" Width="330" Margin="2">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Border Background="{StaticResource ListViewItemPlaceholderBackgroundThemeBrush}" Width="70" Height="70">
                    <Image Source="{Binding Image}" Stretch="UniformToFill" AutomationProperties.Name="{Binding Title}"/>
                </Border>
                <Border Grid.Column="1" BorderThickness="1" Width="260" Height="70" BorderBrush="#FFD3D3D3" Background="{StaticResource HubListItemBackground}" HorizontalAlignment="Left">
                    <StackPanel VerticalAlignment="Bottom" Margin="10,0,0,10" Orientation="Horizontal">
                        <TextBlock Text="{Binding Title}" Style="{StaticResource TitleTextStyle}" TextWrapping="NoWrap" />
                    </StackPanel>
                </Border>
            </Grid>
        </DataTemplate>
        <DataTemplate x:Key="CourseProjectsTemplate">
            <Grid Width="400" Height="600" Style="{StaticResource SectionStyle}">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <TextBlock Text="{Binding Title}" Style="{StaticResource CourseSectionTitleStyle}"  />
                <StackPanel Grid.Row="1" Style="{StaticResource InnerSectionContainerStyle}">
                    <TextBlock Text="{Binding Subtitle}" Style="{StaticResource CourseInnerSectionTitleStyle}"/>
                    <TextBlock Text="{Binding Description}" Style="{StaticResource BodyTextStyle}" Margin="0,10,0,0" />
                    <TextBlock x:Uid="CourseFiles" Text="Files" Style="{StaticResource CourseInnerSectionTitleStyle}" Margin="0,20,0,0" />
                    <ListView Margin="0,20,0,0" Width="330" Height="Auto" ItemsSource="{Binding Files}" ItemTemplate="{StaticResource FilesTemplate}" SelectionMode="None" HorizontalAlignment="Left" IsHitTestVisible="True" IsTapEnabled="True" IsItemClickEnabled="True" />
                </StackPanel>
            </Grid>
        </DataTemplate>

        <DataTemplate x:Key="CourseUnitTemplate">
            <Grid Width="400" Style="{StaticResource SectionStyle}">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <TextBlock x:Uid ="CourseIntroductionTitle" Text="{Binding Title}" Style="{StaticResource CourseSectionTitleStyle}"  />
                <StackPanel Grid.Row="1" Style="{StaticResource InnerSectionContainerStyle}" VerticalAlignment="Top">
                    <TextBlock x:Uid="CourseUnitObjectives" Text="Unit Objectives" Style="{StaticResource CourseInnerSectionTitleStyle}" />
                    <RichTextBlock h2xaml:Properties.Html="{Binding Subtitle}" Margin="0,10,0,0" />
                    <!--<TextBlock Text="{Binding Subtitle}" Style="{StaticResource BodyTextStyle}" Margin="0,10,0,0" />-->
                    <TextBlock x:Uid="CourseFiles" Text="Files" Style="{StaticResource CourseInnerSectionTitleStyle}" Margin="0,20,0,0" />
                    <ListView Margin="0,20,0,0" Width="390" MaxHeight="360" ItemsSource="{Binding ModuleContents}" ItemTemplate="{StaticResource ModuleContentTemplate}" SelectionMode="None" HorizontalAlignment="Left" IsItemClickEnabled="True" ItemClick="CourseFilesItem_Clicked" />
                </StackPanel>
            </Grid>
        </DataTemplate>
    </Page.Resources>

    <!--
        This grid acts as a root panel for the page that defines two rows:
        * Row 0 contains the back button and page title
        * Row 1 contains the rest of the page layout
    -->
    <Page.BottomAppBar>
        <AppBar x:Name="BottomAppBar1" Padding="10,0,10,0" AutomationProperties.Name="Bottom App Bar" Background="{StaticResource MoodleOrangeColor}" Foreground="White">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="50*"/>
                    <ColumnDefinition Width="50*"/>
                </Grid.ColumnDefinitions>
                <StackPanel x:Name="LeftPanel" Orientation="Horizontal" Grid.Column="0" HorizontalAlignment="Left">
                    <Button x:Name="Pin" Style="{StaticResource MoodlePinAppBarButtonStyle}" AutomationProperties.Name="{Binding PinButtonText}" Content="{Binding PinButtonIcon}" Tag="Pin to start" Click="PinClick" />
                </StackPanel>
                <StackPanel x:Name="RightPanel" Orientation="Horizontal" Grid.Column="1" HorizontalAlignment="Right">
                    <Button x:Name="Refresh" Style="{StaticResource MoodleRefreshAppButtonStyle}" Tag="Refresh" Command="{Binding RefreshCommand}"/>
                </StackPanel>
            </Grid>
        </AppBar>
    </Page.BottomAppBar>

    <Grid Style="{StaticResource LayoutRootStyle}">
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!-- Back button and page title -->
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}"/>
            <StackPanel Orientation="Horizontal" Grid.Column="1">
                <TextBlock x:Name="pageTitle" Text="{Binding Course.Fullname}" Style="{StaticResource MoodleAppTitleSyle}"/>
                <local:NavPopup Text="{Binding Info.Sitename}" />
            </StackPanel>
        </Grid>
        <ScrollViewer Grid.Row="1" x:Name="OuterScrollViewer" Margin="0" Style="{StaticResource HorizontalScrollViewerStyle}">
            <ScrollViewer.Background>
                <ImageBrush ImageSource="ms-appx:///Assets/Background.png"/>
            </ScrollViewer.Background>
            <StackPanel Orientation="Horizontal" Margin="90,0,0,0">
                <!--Overview-->
                <Grid Width="360" Style="{StaticResource SectionStyle}">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>
                    <TextBlock x:Uid ="CourseOverviewTitle" Text="Overview" Style="{StaticResource CourseSectionTitleStyle}"  />
                    <Border Grid.Row="1" Background="#999999" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,20,0,50">
                        <StackPanel Style="{StaticResource InnerSectionContainerStyle}">
                            <TextBlock x:Uid="CourseTeachersTitle" Text="Teachers" Style="{StaticResource CourseOverviewSectionStyle}" Margin="20,2,0,0"/>
                            <ListView  x:Name="CourseTeachers" Margin="20,10,20,0" Width="330" Height="Auto" ItemsSource="{Binding Teachers}" ItemTemplate="{StaticResource TeacherTemplate}" SelectionMode="None" HorizontalAlignment="Left" IsItemClickEnabled="True" ItemClick="TeacherClick"/>
                            <Button    x:Uid="CourseParticipantsTitle" Content="Participants >" Style="{StaticResource CourseOverviewSectionButtonStyle}" Margin="20,20,0,0" Command="{Binding GotoUsersCommand}"/>
                            <Button    x:Uid="CourseAssignmentsTitle" Content="Course Assignments >" Style="{StaticResource CourseOverviewSectionButtonStyle}" Margin="20,20,0,0" Command="{Binding GotoNextAssignmentsCommand}"/>
                            <Button    x:Uid="CourseCorrectedAssignmentsTitle" Content="Course Corrected Assignments >" Style="{StaticResource CourseOverviewSectionButtonStyle}" Margin="20,20,0,0" Command="{Binding GotoCorrectedAssignmentsCommand}"/>
                            <Button    x:Uid="CourseEventsTitle" Content="Course Events >" Style="{StaticResource CourseOverviewSectionButtonStyle}" Margin="20,20,0,0" Command="{Binding GotoEventsCommand}"/>
                        </StackPanel>
                    </Border>
                </Grid>
                <ItemsControl ItemsSource="{Binding Units}" ItemTemplate="{StaticResource CourseUnitTemplate}">
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Horizontal" />
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                </ItemsControl>
                <!-- Introduction -->
                <!--<Grid Width="400" Style="{StaticResource SectionStyle}">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>
                    <TextBlock x:Uid ="CourseIntroductionTitle" Text="Introduction" Style="{StaticResource CourseSectionTitleStyle}"  />
                    <StackPanel Grid.Row="1" Style="{StaticResource InnerSectionContainerStyle}" VerticalAlignment="Top">
                        <TextBlock x:Uid="CourseUnitObjectives" Text="Unit Objectives" Style="{StaticResource CourseInnerSectionTitleStyle}" />
                        <TextBlock Text="{Binding CurrentCourse.Introduction}" Style="{StaticResource BodyTextStyle}" Margin="0,10,0,0" />
                        <TextBlock x:Uid="CourseFiles" Text="Files" Style="{StaticResource CourseInnerSectionTitleStyle}" Margin="0,20,0,0" />
                        <ListView x:Name="CourseFilesListview" Margin="0,20,0,0" Width="390" MaxHeight="360" ItemsSource="{Binding CourseFiles}" ItemTemplate="{StaticResource FilesTemplate}" SelectionMode="None" HorizontalAlignment="Left" IsItemClickEnabled="True" ItemClick="CourseFilesItem_Clicked" />
                    </StackPanel>
                </Grid>-->
                <!-- Projects -->
                <!--<Grid x:Name="ProjectsGrid" Style="{StaticResource SectionStyle}" Height="600" VerticalAlignment="Top" >
                    <GridView HorizontalAlignment="Left" ItemsSource="{Binding CourseAssignments}" ItemTemplate="{StaticResource CourseProjectsTemplate}" SelectionMode="None" IsSwipeEnabled="False" IsHitTestVisible="False">
                    </GridView>
                </Grid>-->
            </StackPanel>
        </ScrollViewer>
        <VisualStateManager.VisualStateGroups>

            <!-- Visual states reflect the application's view state -->
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="FullScreenLandscape"/>
                <VisualState x:Name="Filled"/>

                <!-- The entire page respects the narrower 100-pixel margin convention for portrait -->
                <VisualState x:Name="FullScreenPortrait">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PortraitBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>

                <!-- The back button and title have different styles when snapped -->
                <VisualState x:Name="Snapped">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedPageHeaderTextStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</common:LayoutAwarePage>
